Skip to contents

Constructs a model_spec object representing the right-hand side of a regression formula as a set of terms. Accepts unquoted variable names, string literals, or R expressions (e.g. I(x^2)).

Usage

model_spec(..., intercept = TRUE)

# S3 method for class 'model_spec'
print(x, ...)

# S3 method for class 'model_spec'
as.character(x, ...)

Arguments

...

Terms to include. May be unquoted names (cyl), string literals ("cyl"), or R expressions (I(x^2)). To inject a variable whose value is the term name, use !! (bang-bang): model_spec(x1, !!my_var).

intercept

Logical. When FALSE the formula produced by to_formula (and the formula sent to the regression function inside fit_models) will suppress the intercept (equivalent to adding - 1 or 0 + to the formula). Default TRUE.

x

A model_spec object.

Value

A model_spec object.

Examples

model_spec(cyl, disp, hp)
#> model_spec: ~ cyl + disp + hp 
model_spec("cyl", "disp")
#> model_spec: ~ cyl + disp 
model_spec(cyl, I(disp^2))
#> model_spec: ~ cyl + I(disp^2) 
model_spec(cyl, intercept = FALSE)
#> model_spec: ~ 0 + cyl 

# Programmatic use: inject a variable's value with !!
tmp <- "hp"
model_spec(cyl, disp, !!tmp)
#> model_spec: ~ cyl + disp + hp